#include <iostream>
#include "Reactor.hpp"
#include <string>
#include <memory>
#include "Listener.hpp"
#include "PackageParse.hpp"


void Usage(const std::string &process)
{
    std::cout << "Usage: " << process << " server_port" << std::endl;
}


int main(int argc,char* argv[])
{
    //读取port
   if(argc != 2)
   {
        Usage(argv[0]);
        return -1;
   }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<Reactor> R = std::make_unique<Reactor>();

    HandlerConnection hc(PackageParse::Parse);
    //创建Listener
    Listener lt(port,hc);
    R->AddConnection(lt.Sockfd(),
                    EPOLLIN | EPOLLET,
                    std::bind(&Listener::Accepter,&lt,std::placeholders::_1),
                    nullptr,
                    nullptr);
    R->Dispatcher();


    return 0;
}